package pt.inescid.components.policyengine.heimdall.core;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class Stats {

	private static int numberOfLOCs = 0;
	private static int numberOfFiles = 0;
	
	/* ===========================================================
	==============================================================
	==============================================================
	count
	==============================================================
	==============================================================
	=========================================================== */
	public static void count(File currentPath) throws Exception {

		int currentLOCs = 0;
		
		if (currentPath.isDirectory()) {
			File[] allFiles = currentPath.listFiles();
			
			for (int i = 0; i < allFiles.length; i++) {
				count(allFiles[i]);
			}
		}
		else if (currentPath.isFile()) {
			BufferedReader bf =
				new BufferedReader(new FileReader(currentPath));
			
			while (bf.readLine() != null) {
				currentLOCs++;
			}
			
			bf.close();
			
			
			numberOfFiles++;
			numberOfLOCs += currentLOCs;
			
			System.out.println(currentLOCs + " LOCs: " + 
					currentPath.getAbsolutePath());

		}
	} // count

	
	
	/* ===========================================================
	==============================================================
	==============================================================
	main
	==============================================================
	==============================================================
	=========================================================== */
	public static void main(String[] args) {

		try {
			count(new File("G:/docs/Projectos/heimdall/src2"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		System.out.println("\n\n" + numberOfLOCs + " LOCs in " +
				numberOfFiles + " files.");
	} // main
}; // MainConsole
